from django.utils.deprecation import MiddlewareMixin
from jilu.models import *
from django.db.models import F
class MD1(MiddlewareMixin):
    def process_request(self,request):
        print('MD1的process_request--运行')
        if 'HTTP_X_FORWARDED_FOR' in request.META:  # 获取用户真实IP地址
            user_ip = request.META['HTTP_X_FORWARDED_FOR']
        else:
            user_ip = request.META['REMOTE_ADDR']
        print(user_ip)
        if user_ip!=user_ip:
            Statistics.objects.filter(id=1).update(count=F('count')+1)

    def process_view(self,request,view_func,view_args,view_kwargs):
        print('MD1的process_view--运行')

    def process_response(self,request,response):
        print('MD1的process_response--运行')
        return response
    def process_exception(self,request,exception):
        print('MD1的process_exception--运行')
